<template>
  <div>
    <el-dialog :title="title" :visible.sync="dialogVisble" :before-close="handleClose" :close-on-click-modal=false
               width="30%">
      <el-form :model="form" label-position="left" label-width="100px" ref="form" :rules="rules">
        <el-form-item label="配置名称" prop="name">
          <el-input v-model="form.name" autocomplete="off" maxlength="50" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="配置描述" prop="description">
          <el-input type="textarea" v-model="form.description" autocomplete="off" maxlength="200" show-word-limit></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="save()">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
export default {
  name: "cuDialog",
  props: ["dialogVisble", "content", "operateId"],
  data() {
    return {
      title: "保存配置",
      form: {
        name: "",
        description: "",
        operateId: ""
      },
      rules: {
        name: [{required: true, message: '配置名称不能为空', trigger: 'blur'}],
        description: [{required: true, message: '配置描述不能为空', trigger: 'blur'}],
      }
    }
  },
  watch: {
    dialogVisble() {
      this.form = {
        name: "",
        description: "",
        operateId: ""
      }
    }
  },
  methods: {
    handleClose() {
      this.$emit("closeDialog")
    },
    save() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.form.createUser = this.$store.state.user.userId
          this.form.content = JSON.stringify({...this.content})
          this.form.operateId = this.operateId
          this.api({url: "/addCaseConfig", method: "post", data: this.form}).then(resp => {
            this.$message({message: resp, type: 'success'});
            this.handleClose()
          })
        }
      })

    }
  },
}
</script>

<style scoped>

</style>
